<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/form/show/index.css">
    <link rel="stylesheet" href="/form/show/FormMaking.css">
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <script type="text/javascript" src="../../js/commonJs.js"></script>
</head>
<body>
<div id="app">
    <fm-generate-form
            :data="jsonData"
            :remote="remoteFuncs"
            :value="editData"
            ref="generateForm"
    >
    </fm-generate-form>
<!--    <el-button type="primary" @click="handleSubmit">提交</el-button>-->
</div>
<script src="/form/show/vue.js"></script>
<script src="/form/show/index.js"></script>
<script src="/form/show/FormMaking.umd.js"></script>
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
<script>
    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
    })(jQuery);

    var cc;

    $(function () {
        //alert(window.location.href);
        var formKey = $.getUrlParam('formKey');
        var taskId = $.getUrlParam('taskId');
       // alert("formKey:"+formKey);
       // alert(taskId)
        $.ajax({
            type: 'POST',
            url: '/history/historyProcessVariabless?taskId=' + taskId,
            dataType: 'json',
            success: function (data) {
                var editData = data;
                console.log("dddd:"+JSON.stringify(data))
              //  alert(":::" + JSON.stringify(data))
                //formKey = "2a0ce77e-d438-4624-87f8-44cf31458f1a";
                var jsonArray = [];

                var obj = {'column': "uuid", 'type': 'eq', "value": formKey};

                jsonArray.push(obj)

                $.ajax({
                    type: 'POST',
                    url: '/form-info/find',
                    dataType: 'json',
                    data: {paramData: JSON.stringify(jsonArray)},
                    success: function (data) {
                        var jsonstr = eval(eval(data).data).content
                        cc = new Vue({
                            el: '#app',
                            data: {
                                jsonData: JSON.parse(jsonstr),
                                editData: editData,
                                remoteFuncs: {}
                            },
                            methods: {
                                handleSubmit () {
                                    this.$refs.generateForm.getData().then(data => {

                                        $.ajax({
                                            type: 'POST',
                                            contentType: "application/json;charset=UTF-8",
                                            url: '/runtime/tasks/do/'+taskId,
                                            dataType: 'json',
                                            data:JSON.stringify(data),
                                            //data:'{"dealType":"0","dealReason":"eeeee"}',
                                            success: function(data){
                                                layer.msg('提交成功！!',{icon:1,time:1000});
                                            },
                                            error:function(data) {
                                                console.log(data.msg);
                                            },
                                        });
                                }).catch(e => {
                                        // data check failed
                                    })
                                }
                            }
                        })
                    },
                    error: function (data) {
                        // console.log(data.msg);
                    },
                });
            },
            error: function (data) {
                // console.log(data.msg);
            },
        });
    })

    function appletest() {
        cc.handleSubmit();
    }

</script>
</body>
</html>